home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_388 / free / output.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  82 lines

  1. /***************************************************************************
  2.  * output.c:    Functions for printing the output.
  3.  *
  4.  * Part of...
  5.  *
  6.  *    FREE:    Display free space on your disk volumes.
  7.  *        Author:  Daniel Jay Barrett, barrett@cs.jhu.edu.
  8.  *
  9.  * This program is Freely Distributable.  Make all the copies you want
  10.  * and give them away.  Use this code in any way you like.
  11. ***************************************************************************/
  12.  
  13. #include "free.h"
  14.  
  15. /* Show the amount of free space on the volume. */
  16.  
  17. void ShowFree(char *volume, long chipRam, long fastRam, char out[])
  18. {
  19.     if (ValidDriveName(volume))
  20.     {
  21.         if (!StrCaseCmp(volume, "RAM:"))
  22.             ShowFreeRam(chipRam, fastRam, out);
  23.         else
  24.             DoNormalDrive(volume, out);
  25.     }
  26.     else
  27.         fprintf(stderr, "ERROR!  \"%s\" MUST END WITH '%c'.\n",
  28.             volume, VOLUME_END_CHAR);
  29. }
  30.  
  31.  
  32. /* Copy "free RAM" information into the buffer "out[]".  We use
  33.  * MakeFormatString() to make sure that the CHIP RAM amount is
  34.  * properly indented to match other output... and then just hack
  35.  * the FAST RAM and TOTAL RAM values onto the end.  If you have no FAST
  36.  * RAM, you won't see these last two values. */
  37.  
  38. void ShowFreeRam(long chip, long fast, char out[])
  39. {
  40.     char tmp[BUFSIZ];    /* This should hold 1 line of output... */
  41.     char formatString[FORMAT_LENGTH];
  42.  
  43.     MakeFormatString("Chip", formatString, 'd', NO_CR);
  44.     sprintf(tmp, formatString, HI_ON, "Chip", HI_OFF, chip);
  45.     Concat(out, tmp);
  46.  
  47.     if (fast)
  48.     {
  49.         sprintf(tmp, "   %s%s%s%10ld   %s%s%s%9ld",
  50.             HI_ON, "Fast", HI_OFF, fast,
  51.                HI_ON, "Total", HI_OFF, chip+fast);
  52.         Concat(out, tmp);
  53.     }
  54.  
  55.     Concat(out, "\n");
  56. }
  57.  
  58.  
  59. /* Find the free space on a normal disk drive, and append it to the
  60.  * buffer "out[]".  We use MakeFormatString() for matching indenting. */
  61.  
  62. void DoNormalDrive(char *volume, char out[])
  63. {
  64.     long mem;
  65.     char tmp[BUFSIZ];    /* This should hold 1 line of output... */
  66.     char formatString[FORMAT_LENGTH];
  67.  
  68.     mem = GetMem(volume);
  69.  
  70.     if (mem != NO_DRIVE)
  71.     {
  72.         MakeFormatString(volume, formatString, 'd', CR);
  73.         sprintf(tmp, formatString, HI_ON, volume, HI_OFF, mem);
  74.     }
  75.     else
  76.     {
  77.         MakeFormatString(volume, formatString, 's', CR);
  78.         sprintf(tmp, formatString, HI_ON, volume, HI_OFF, NONE);
  79.         }
  80.     Concat(out, tmp);
  81. }
  82.